﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using VehicleMaintenance.Models;
using VehicleMaintenance.Comm;

namespace VehicleMaintenance.Framework
{
    public partial class AddOrEditBaseForm : BaseForm
    {

        #region 私有变量及属性

        /// <summary>
        /// 当前窗口状态
        /// </summary>
        protected State state = State.Add;

        /// <summary>
        /// 当前处理数据类型，对应数据库表
        /// </summary>
        protected Type type;

        #endregion 私有变量及属性

        #region 构造函数


        public AddOrEditBaseForm()
        {
            InitializeComponent();
        }

        public AddOrEditBaseForm(Type t)
        {
            InitializeComponent();

            type = t;

            //VehicleMaintenance.Comm.UIControl.CreatControls(type, tabPanel);
        }

        //public AddOrEditBaseForm(Type t, EventHandler txt_GotFocus)
        //{
        //    InitializeComponent();

        //    type = t;

        //    VehicleMaintenance.Comm.UIControl.CreatControls(type, tabPanel, txt_GotFocus);
        //}


        #endregion 构造函数

        #region 事件

        private void btnClose_Click(object sender, EventArgs e)
        {
            try
            {
                this.Close();
            }
            catch (Exception ex)
            {
                this.ShowInfo(ex.Message);
            }
        }

        #endregion 事件

        #region 保护方法

        /// <summary>
        /// 清空当前窗体的所有数据
        /// </summary>
        /// <param name="con"></param>
        protected void ClearData(Control con)
        {
            foreach (Control item in con.Controls)
            {
                if (item is TextBox)
                {
                    ((TextBox)item).Clear();
                }
                else if (item is ComboBox)
                {
                    ((ComboBox)item).SelectedIndex = 0;
                }
                ClearData(item);
            }
        }

        #endregion 保护方法

        //private void AddOrEditBaseForm_KeyDown(object sender, KeyEventArgs e)
        //{
        //    try
        //    {
        //        if (e.KeyCode == Keys.Enter)
        //        {
        //            SendKeys.Send("{TAB}");
        //        }               
        //    }
        //    catch (Exception ex)
        //    {
        //        this.ShowInfo(ex.Message);
        //    }
        //}

        private void AddOrEditBaseForm_KeyUp(object sender, KeyEventArgs e)
        {
            try
            {
                if (e.KeyCode == Keys.Enter)
                {
                    SendKeys.Send("{TAB}");
                }
            }
            catch (Exception ex)
            {
                this.ShowInfo(ex.Message);
            }
        }
    }
}
